import 'package:flutter/material.dart';
import 'package:whale/helper/utils/util.dart';

import 'config.dart';

part 'tab_bar.dart';

mixin TabBarMixin {
  ITabBar indicatorTabBar({
    required TabController? controller,
    required List<String>? titles,
    bool scrollable = false,
    TabbarConfig? config,
  }) {
    return ITabBar(
      ctrl: controller,
      tabs: titles == null ? null : tabTitles(titles),
      isScrollable: scrollable,
      config: config ?? TabbarConfig.line(),
    );
  }

  ITabBar bgTabBar({
    required TabController? controller,
    required List<String>? titles,
    bool scrollable = false,
    TabbarConfig? config,
  }) {
    return ITabBar(
      ctrl: controller,
      tabs: titles == null ? null : tabTitles(titles),
      isScrollable: scrollable,
      config: config ?? TabbarConfig.bg(),
    );
  }

  List<Widget> tabTitles(List<String> titles) {
    return titles
        .asMap()
        .map(
          (i, val) => MapEntry(
              i,
              Tab(
                text: val,
              )),
        )
        .values
        .toList();
  }
}
